#!/bin/bash

server_keystore=server.keystore
server_keystore_pass=111111

server_key=n_server.key
server_key_pass=111111
server_cert=n_server.crt

server_p12=n_server.p12
server_p12_pass=$server_key_pass

echo "convert keystore $server_keystore to p12: $server_p12"
keytool -importkeystore -srckeystore $server_keystore  -destkeystore $server_p12 \
    -srcstoretype jks -deststoretype pkcs12 -srcalias server -destalias server \
    -deststorepass $server_p12_pass -srcstorepass $server_keystore_pass
	
echo "export server cert: $server_cert"
openssl pkcs12 -in $server_p12 -clcerts -nokeys -password pass:$server_p12_pass -out $server_cert
echo "export server key(pkcs8): $server_key"
openssl pkcs12 -in $server_p12 -nocerts -password pass:$server_p12_pass -passout pass:$server_key_pass -out $server_key